<?php

/**
 *      This is NOT a freeware, use is subject to license terms
 *      应用名称: 大疆社区自适应版 商业版
 *      下载地址: https://addon.dismall.com/templates/quater_2023_dji.html
 *      应用开发者: Q设计
 *      开发者QQ: 2243108352
 *      更新日期: 202312221544
 *      授权域名: dc.rpa-china.cn
 *      授权码: 2023122215WuZLgUgZUt
 *      未经应用程序开发者/所有者的书面许可，不得进行反向工程、反向汇编、反向编译等，不得擅自复制、修改、链接、转载、汇编、发表、出版、发展与之有关的衍生产品、作品等
 */

if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}

//导航我的收藏
$forum_favorites = DB::fetch_all("SELECT a.*,b.name,b.todayposts,c.icon,c.description as forum_description FROM ".DB::table('home_favorite')." a LEFT JOIN ".DB::table('forum_forum')." b on b.fid=a.id LEFT JOIN ".DB::table('forum_forumfield')." c on c.fid=b.fid WHERE a.`idtype`= 'fid' AND a.`uid`='$_G[uid]' ORDER BY a.`dateline` DESC LIMIT 0,10");//版块

// 我关注的版块fids


// 我关注的用户uids
$followinglists=DB::fetch_all("SELECT followuid FROM ".DB::table("home_follow")." WHERE `uid`=$_G[uid] ORDER BY `dateline` DESC");
foreach ($followinglists as $key => $value) {
	$followinglists[$key] = $value['followuid'];
}
$myfvuids = implode(",", $followinglists);

$fids='1000';//不调用的版块，多个用半角逗号分开
if(!$_GET['from'] || $_GET['from']==''){
	$from="t.`fid` NOT in ($fids) and";
}elseif($_GET['from']=='myfavf'){
	if($myfvfids){
			$from="t.`fid` in ($myfvfids) and";
		}else{
			$from="t.`fid` in ('10000') and";
		}
}elseif($_GET['from']=='myfavt'){
	$from="t.`fid` NOT in ($fids) and FIND_IN_SET (t.`authorid`,'$myfvuids') and";
	}

$orderby='t.`lastpost` desc';
$order = $_GET['order']; //排序方式 dateline lastpost replies views rand()
if($order&&in_array($order,array('dateline','replies','views'))){
	$orderby="t.`$order` desc";
}elseif($order=='rand'){
	$orderby="rand()";
	}
if($_GET['type'] == 'digest'){
	$type = 'and t.`digest`>0';
}
elseif($_GET['type'] == 'recommend'){
	$type = 'and t.`stamp`=5';
}
elseif($_GET['type'] == 'displayorder'){
	$type = 'and t.`displayorder`>0';
}
elseif($_GET['type'] == 'favorite'){
	$type = "and h.`idtype`= 'tid' AND h.`uid`='$_G[uid]'";
}
else{
	$type = '';
}
if($_GET['from']=='myfavf' || $_GET['from']=='myfavt' || $_GET['order']=='rand' || $_GET['type'] == 'digest' || $_GET['type'] == 'recommend' || $_GET['type'] == 'favorite'){
	$dp = '';
}
else{
	$dp = 't.displayorder DESC,';
}

//首页帖子主列表
$tnum=20;
$begin=($_G['page']-1)*$tnum;
$manylist=array();
require_once libfile('function/post');
$rs=DB::query("SELECT t.*,p.pid,f.name,h.id,h.idtype,i.extra from ".DB::table("forum_thread")." t LEFT JOIN ".DB::table("forum_post")." p on p.tid=t.tid LEFT JOIN ".DB::table("forum_forum")." f on f.fid=t.fid LEFT JOIN ".DB::table("home_favorite")." h on h.id=t.tid LEFT JOIN ".DB::table("forum_forumfield")." i on i.fid=t.fid WHERE $from t.displayorder>=0 and p.first=1 and f.status=1 $type group by t.tid ORDER BY $dp $orderby LIMIT $begin , $tnum");
while ($rw=DB::fetch($rs)) {
	$rw['lastposterenc']=urlencode($rw['lastposter']);
	$rw['lastposterid']=DB::result_first("select authorid from ".DB::table("forum_post")." where tid='$rw[tid]' and first=0 ORDER BY pid desc");
	$rw['extra'] = unserialize(stripslashes($rw['extra']));// forumcolor
	//$rw['dateline'] = dgmdate($rw['dateline'], 'u', '9999', getglobal('setting/dateformat')); //$rw['dateline'] = dgmdate($rw['dateline'],'Y-m-d H:i');
    $rw['rushreply'] = getstatus($rw['status'], 3);

	 if($rw['highlight']) {
        $colorarray = array('', '#EE1B2E', '#EE5023', '#996600', '#3C9D40', '#2897C5', '#2B65B7', '#8F2A90', '#EC1282');
		$string = sprintf('%02d', $rw['highlight']);
		$stylestr = sprintf('%03b', $string[0]);
		$rw['highlight'] = 'style="';
		$rw['highlight'] .= $stylestr[0] ? 'font-weight: bold;' : '';
		$rw['highlight'] .= $stylestr[1] ? 'font-style: italic;' : '';
		$rw['highlight'] .= $stylestr[2] ? 'text-decoration: underline;' : '';
		$rw['highlight'] .= $string[1] ? 'color: '.$colorarray[$string[1]] : '';
		$rw['highlight'] .= '"';
	} else {
		$rw['highlight'] = '';
	} 
	$manylist[]=$rw;
}
loadcache('stamps');

$allnum=DB::result_first("select count(*) from ".DB::table("forum_thread")." t left join ".DB::table("forum_post")." p on p.tid=t.tid LEFT JOIN ".DB::table("home_favorite")." h on h.id=t.tid where $from p.first=1 $type");
if($_GET['from']){
	$fm="from=$_GET[from]&";
}
if($_GET['type']){
	$tp="type=$_GET[type]&";
}
$pagenav=multi($allnum,$tnum,$_G['page'],"portal.php?{$fm}{$tp}order=$order");
$ntpage=$_G['page']+1;
$fynum=ceil($allnum/$tnum);


// 用户所有信息
function user_info($useruid){
$user_infos = DB::fetch_all("select a.*,b.*,c.*,d.*,e.* from ".DB::table("common_member")." a LEFT JOIN ".DB::table("common_usergroup")." b on b.groupid=a.groupid LEFT JOIN ".DB::table("common_member_count")." c on c.uid=a.uid LEFT JOIN ".DB::table("common_member_profile")." d on d.uid=a.uid LEFT JOIN ".DB::table("common_usergroup_field")." e on e.groupid=b.groupid where a.`uid` = '$useruid' AND b.`allowvisit` > 0");
	return $user_infos[0];
}

// 公告列表
$notices = DB::fetch_all("select a.*,b.username,b.uid from ".DB::table("forum_announcement")." a LEFT JOIN ".DB::table("common_member")." b on b.username=a.author order by `displayorder` asc limit 0,10");//时间控制 where `endtime`>'$_G[timestamp]'

//友情链接
$friendlinks = DB::fetch_all("SELECT id,name,url,description,logo FROM ".DB::table('common_friendlink')." WHERE `type`> 0 ORDER BY `displayorder` ASC LIMIT 0, 10");

/**
 * array_column() // 不支持低版本;
 * 以下方法兼容PHP低版本
 */
if (!function_exists('array_column')) {
    function array_column($array, $column_key, $index_key = null) {
        $column_key_isNumber = (is_numeric($column_key)) ? true : false;
        $index_key_isNumber  = (is_numeric($index_key)) ? true : false;
        $index_key_isNull    = (is_null($index_key)) ? true : false;
         
        $result = array();
        foreach((array)$array as $key=>$val){
            if($column_key_isNumber){
                $tmp = array_slice($val, $column_key, 1);
                $tmp = (is_array($tmp) && !empty($tmp)) ? current($tmp) : null;
            } else {
                $tmp = isset($val[$column_key]) ? $val[$column_key] : null;
            }
            if(!$index_key_isNull){
                if($index_key_isNumber){
                    $key = array_slice($val, $index_key, 1);
                    $key = (is_array($key) && !empty($key)) ? current($key) : null;
                    $key = is_null($key) ? 0 : $key;
                }else{
                    $key = isset($val[$index_key]) ? $val[$index_key] : 0;
                }
            }
            $result[$key] = $tmp;
        }
        return $result;
    }
}

//版块图标及版主头像
$forumicon = DB::result(DB::query("SELECT icon FROM ".DB::table('forum_forumfield')." WHERE `fid`= '$_G[fid]'"));
$forumbzs = DB::fetch_all("SELECT a.*,b.* FROM ".DB::table("forum_moderator")." a LEFT JOIN ".DB::table("common_member")." b on b.uid=a.uid WHERE a.`fid` = '$_G[fid]'");

    		  	  		  	  		     	  		      		   		     		       	  	 		    		   		     		       	  	 		    		   		     		       	  	 		    		   		     		       	  			     		   		     		       	  			     		   		     		       	  				    		 	      	  		  	  		     	
?>